/*
 * SongGUI.java
 *
 * Created on den 15 december 2007, 19:24
 * 
 * Naive attempt to play midi file in GUI
 * (no thread handling, only calling the player method directoy)
 */

package rehearser;

import javax.swing.SwingWorker;

/**
 *
 * @author  Martin Gumucio
 * @TODO Implement Start button to play a midi file
 * @TODO Implement Mute buttons
 * @TODO Implement timecounter and barcounter
 * @TODO Implement Slider
 */
public class SongGUI extends javax.swing.JFrame {
    
    /** Creates new form SongGUI */
    public SongGUI() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        titleLabel = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        chan5MuteButton = new javax.swing.JToggleButton();
        chan1MuteButton = new javax.swing.JToggleButton();
        chan9MuteButton = new javax.swing.JToggleButton();
        chan13MuteButton = new javax.swing.JToggleButton();
        chan14MuteButton = new javax.swing.JToggleButton();
        chan15MuteButton = new javax.swing.JToggleButton();
        chan16MuteButton = new javax.swing.JToggleButton();
        chan6MuteButton = new javax.swing.JToggleButton();
        chan2MuteButton = new javax.swing.JToggleButton();
        chan3MuteButton = new javax.swing.JToggleButton();
        chan7MuteButton = new javax.swing.JToggleButton();
        chan8MuteButton = new javax.swing.JToggleButton();
        Chan4MuteButton = new javax.swing.JToggleButton();
        chan10MuteButton = new javax.swing.JToggleButton();
        chan11MuteButton = new javax.swing.JToggleButton();
        chan12MuteButton = new javax.swing.JToggleButton();
        startStopButton = new javax.swing.JButton();
        Pause = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        timeLabel = new javax.swing.JLabel();
        jSlider1 = new javax.swing.JSlider();
        channelslabel = new javax.swing.JLabel();
        songTitleLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        titleLabel.setFont(new java.awt.Font("Dialog", 0, 24));
        titleLabel.setText("Rehearser");

        chan5MuteButton.setSelected(true);
        chan5MuteButton.setText("5");

        chan1MuteButton.setSelected(true);
        chan1MuteButton.setText("1");
        chan1MuteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chan1MuteButtonActionPerformed(evt);
            }
        });

        chan9MuteButton.setSelected(true);
        chan9MuteButton.setText("9");

        chan13MuteButton.setSelected(true);
        chan13MuteButton.setText("13");

        chan14MuteButton.setSelected(true);
        chan14MuteButton.setText("14");

        chan15MuteButton.setSelected(true);
        chan15MuteButton.setText("15");

        chan16MuteButton.setSelected(true);
        chan16MuteButton.setText("16");

        chan6MuteButton.setSelected(true);
        chan6MuteButton.setText("6");

        chan2MuteButton.setSelected(true);
        chan2MuteButton.setText("2");

        chan3MuteButton.setSelected(true);
        chan3MuteButton.setText("3");

        chan7MuteButton.setSelected(true);
        chan7MuteButton.setText("7");

        chan8MuteButton.setSelected(true);
        chan8MuteButton.setText("8");

        Chan4MuteButton.setSelected(true);
        Chan4MuteButton.setText("4");

        chan10MuteButton.setSelected(true);
        chan10MuteButton.setText("10");

        chan11MuteButton.setSelected(true);
        chan11MuteButton.setText("11");

        chan12MuteButton.setSelected(true);
        chan12MuteButton.setText("12");

        startStopButton.setText("Start");
        startStopButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startStopButtonActionPerformed(evt);
            }
        });

        Pause.setActionCommand("Pause");
        Pause.setLabel("Pause");

        jLabel1.setFont(new java.awt.Font("Dialog", 0, 18));
        jLabel1.setText("0.0.0");

        timeLabel.setFont(new java.awt.Font("Dialog", 0, 36));
        timeLabel.setText("00:00:00");

        jSlider1.setForeground(new java.awt.Color(0, 0, 0));

        channelslabel.setText("Channels");

        songTitleLabel.setText("Song Title goes here");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, chan5MuteButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, chan1MuteButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, chan9MuteButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, chan13MuteButton))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(layout.createSequentialGroup()
                                        .add(chan14MuteButton)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(chan15MuteButton)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(chan16MuteButton))
                                    .add(layout.createSequentialGroup()
                                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(layout.createSequentialGroup()
                                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                                    .add(chan6MuteButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                    .add(chan2MuteButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE))
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                                    .add(chan3MuteButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
                                                    .add(chan7MuteButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE))
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                                    .add(chan8MuteButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                    .add(Chan4MuteButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)))
                                            .add(layout.createSequentialGroup()
                                                .add(chan10MuteButton)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(chan11MuteButton)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(chan12MuteButton)))
                                        .add(49, 49, 49)))
                                .add(168, 168, 168))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(Pause, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 70, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(startStopButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 72, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(jLabel1)
                                    .add(timeLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                                    .add(songTitleLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addContainerGap())
                    .add(layout.createSequentialGroup()
                        .add(channelslabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)
                        .add(180, 180, 180))
                    .add(layout.createSequentialGroup()
                        .add(jSlider1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 356, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(71, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(titleLabel)
                        .addContainerGap(313, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 305, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(122, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(titleLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(songTitleLabel)
                    .add(startStopButton))
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(1, 1, 1)
                        .add(timeLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel1))
                    .add(layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(Pause)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSlider1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(44, 44, 44)
                .add(channelslabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(chan1MuteButton)
                    .add(chan2MuteButton)
                    .add(chan3MuteButton)
                    .add(Chan4MuteButton))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(chan5MuteButton)
                    .add(chan6MuteButton)
                    .add(chan7MuteButton)
                    .add(chan8MuteButton))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(chan10MuteButton)
                    .add(chan11MuteButton)
                    .add(chan12MuteButton)
                    .add(chan9MuteButton))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(chan13MuteButton)
                    .add(chan14MuteButton)
                    .add(chan15MuteButton)
                    .add(chan16MuteButton))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void chan1MuteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chan1MuteButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_chan1MuteButtonActionPerformed

    private void startStopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startStopButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_startStopButtonActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SongGUI().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToggleButton Chan4MuteButton;
    private javax.swing.JButton Pause;
    private javax.swing.JToggleButton chan10MuteButton;
    private javax.swing.JToggleButton chan11MuteButton;
    private javax.swing.JToggleButton chan12MuteButton;
    private javax.swing.JToggleButton chan13MuteButton;
    private javax.swing.JToggleButton chan14MuteButton;
    private javax.swing.JToggleButton chan15MuteButton;
    private javax.swing.JToggleButton chan16MuteButton;
    private javax.swing.JToggleButton chan1MuteButton;
    private javax.swing.JToggleButton chan2MuteButton;
    private javax.swing.JToggleButton chan3MuteButton;
    private javax.swing.JToggleButton chan5MuteButton;
    private javax.swing.JToggleButton chan6MuteButton;
    private javax.swing.JToggleButton chan7MuteButton;
    private javax.swing.JToggleButton chan8MuteButton;
    private javax.swing.JToggleButton chan9MuteButton;
    private javax.swing.JLabel channelslabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSlider jSlider1;
    private javax.swing.JLabel songTitleLabel;
    private javax.swing.JButton startStopButton;
    private javax.swing.JLabel timeLabel;
    private javax.swing.JLabel titleLabel;
    // End of variables declaration//GEN-END:variables
    
    /**
     * THe swingworker threads purpose is to keep the GUI responsive
     * while playing the midi file
     * 
     */
//    SwingWorker worker = new SwingWorker<ImageIcon[], Void>() {
//    @Override
//    public ImageIcon[] doInBackground() {
//        /**
//         *  Method runs while song is playing
//         * 
//         */
//        final ImageIcon[] innerImgs = new ImageIcon[nimgs];
//        for (int i = 0; i < nimgs; i++) {
//            innerImgs[i] = loadImage(i+1);
//        }
//        return innerImgs;
//    }
//
//    @Override
//    public void done() {
//        //Remove the "Loading images" label.
//        animator.removeAll();
//        loopslot = -1;
//        try {
//            imgs = get();
//        } catch (InterruptedException ignore) {}
//        catch (java.util.concurrent.ExecutionException e) {
//            String why = null;
//            Throwable cause = e.getCause();
//            if (cause != null) {
//                why = cause.getMessage();
//            } else {
//                why = e.getMessage();
//            }
//            System.err.println("Error retrieving file: " + why);
//        }
//    }
};
    
//}
